package com.woniuxy.service.impl;

import com.woniuxy.service.AccountService;
import com.woniuxy.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class PaymentServiceImpl implements PaymentService {
    @Autowired
    private AccountService accountService;
    /**
     * 所谓事务的传播行为，是存在于事务嵌套的情况下要设置
     */
    @Transactional
    @Override
    public void payment(int type, String fromAccountno, String toAccountno, float money)throws Exception{
        switch (type){
            case 1:
                if(money>20000){
                    float sy=money-(float)(money-2000*0.001);
                    accountService.transfer(fromAccountno,toAccountno,sy);
                }
                break;
            case 2:
                if(money>30000){
                    float sy=money-(float)(money-3000*0.001);
                    accountService.transfer(fromAccountno,toAccountno,sy);
                }
                break;
            case 3:
                if(money>50000){
                    float sy=money-(float)(money-5000*0.001);
                    accountService.transfer(fromAccountno,toAccountno,sy);
                }
                break;
        }
    }
}
